package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.dto.RetailBreedFactoryDto;
import com.jiantong.user.impl.manager.RetailBreedFactoryManager;
import com.jiantong.user.service.RetailBreedFactoryWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by mz on 10/7/17.
 *
 */
@RpcProvider
@Slf4j
@Service
public class RetailBreedFactoryWriteServiceImpl implements RetailBreedFactoryWriteService{

    private final RetailBreedFactoryManager retailBreedFactoryManager;

    @Autowired
    public RetailBreedFactoryWriteServiceImpl(RetailBreedFactoryManager retailBreedFactoryManager) {
        this.retailBreedFactoryManager = retailBreedFactoryManager;
    }

    /**
     *
     * @param retailBreedFactoryDto 养殖场的dto
     * @return Map<String , Object>
     */
    @Override
    public Response<Map<String , Object>> createRetailBreedFactory(RetailBreedFactoryDto retailBreedFactoryDto) {

        try{
            return Response.ok(retailBreedFactoryManager.createRetailBreedFactory(retailBreedFactoryDto));
        }catch (Exception e){
            log.error("failed to create retail breed factory case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to create retail breed factory");
        }
    }

    /**
     *
     * @param retailBreedFactoryDto 养殖场的dto
     * @return Map<String , Object>
     */
    @Override
    public Response<Map<String, Object>> updateRetailBreedFactory(RetailBreedFactoryDto retailBreedFactoryDto) {
        try{
            return Response.ok(retailBreedFactoryManager.updateRetailBreedFactory(retailBreedFactoryDto));
        }catch (Exception e){
            log.error("failed to update retail breed factory case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to update retail breed factory");
        }
    }
}
